/*****************************************************************************
 
    SlkError.c
  
    Version 7.50
  
    Parse error recovery routines.
 
    Copyright (c) 2002-2014  SLK Systems, all rights reserved.
    
******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "SlkError.h"
#include "SlkString.h"

#define GET_SYMBOL_NAME    SlkGetSymbolName 

// -----------------------------------------------------------------------
//  mismatch
// -----------------------------------------------------------------------

INSTANCE_METHOD
slk_size_t
(mismatch) ( error_t    *d,
             slk_size_t  terminal,
             slk_size_t  token )
{
    printf ( "  expecting '%s' but found '%s' \n", GET_SYMBOL_NAME (terminal),
                                                   GET_SYMBOL_NAME (token) );
    return  token;
}

// -----------------------------------------------------------------------
//  no_entry
//
//  The symbol is a nonterminal. No parse table entry was found.
//
// -----------------------------------------------------------------------

INSTANCE_METHOD
slk_size_t
(no_entry) ( error_t    *d,
             slk_size_t  nonterminal,
             slk_size_t  token,
             int         level )
{
    printf ( "  syntax error: skipping input '%s' \n", GET_SYMBOL_NAME(token));

    token = get_attribute(d->peeker);         // advance the input
//  token = 0;                                  // LR

    return  token;
}

// -----------------------------------------------------------------------
//  input_left
//
//  The parse stack is empty, but input is still remaining.
//  Usually happens after an improperly recovered error.
//
// -----------------------------------------------------------------------

INSTANCE_METHOD
void
(input_left) ( error_t  *d )
{
}

// -----------------------------------------------------------------------
// message 
// -----------------------------------------------------------------------

INSTANCE_METHOD
void  
(message) ( error_t  *d,
            char     *message )
{
    fputs ( message, stdout );
}

// -----------------------------------------------------------------------
// InitializeError
// -----------------------------------------------------------------------

PUBLIC
void
InitializeError ( error_t   *error,
                  peeker_t  *peeker )
{
    error->peeker = peeker;
    error->mismatch = mismatch;
    error->no_entry = no_entry;
    error->input_left = input_left;
    error->message = message;
}
